package com.xysq.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.rockcent.action.CallbackListener;
import com.rockcent.model.CouponBO;
import com.rockcent.model.CouponModel;
import com.xysq.adapter.CategoryAdapter;
import com.xysq.lemon.R;
import com.xysq.util.ToastUtil;

import java.util.List;

import butterknife.InjectView;

/**
 * @author 黄东凯
 */
public class CategoryActivity extends BaseActivity implements View.OnClickListener {
    //以下参数无输入，统一初始化为0或空
    private int modelType = 0;//券类别
    private String keyword = "";//行业类别ID
    private int listType = 0;//排序类型
    private int locationId = 0;//城市ID
    private int industryId = 1;
    private CategoryAdapter categoryAdapter;
    @InjectView(R.id.btn_book)
    Button bookBtn;
    @InjectView(R.id.btn_curing)
    Button curingBtn;
    @InjectView(R.id.btn_food)
    Button foodBtn;
    @InjectView(R.id.btn_handwork)
    Button handwordBtn;
    @InjectView(R.id.btn_machine)
    Button machineBtn;
    @InjectView(R.id.btn_outside)
    Button outsideBtn;
    @InjectView(R.id.btn_second_hand)
    Button secondHandBtn;
    @InjectView(R.id.btn_my_service)
    Button myServieBtn;
    @InjectView(R.id.btn_use_live)
    Button useLiveBtn;
    @InjectView(R.id.btn_stationery)
    Button stationeryBtn;
    @InjectView(R.id.list_data)
    ListView dataList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category);
        initViews();
        getDatas(5);
    }

    private void initViews() {
        bookBtn.setOnClickListener(this);
        curingBtn.setOnClickListener(this);
        foodBtn.setOnClickListener(this);
        handwordBtn.setOnClickListener(this);
        myServieBtn.setOnClickListener(this);
        outsideBtn.setOnClickListener(this);
        machineBtn.setOnClickListener(this);
        secondHandBtn.setOnClickListener(this);
        useLiveBtn.setOnClickListener(this);
        stationeryBtn.setOnClickListener(this);
        categoryAdapter = new CategoryAdapter(this);
        dataList.setAdapter(categoryAdapter);
    }

    private void getDatas(int industryId) {
        appAction.listCouponModel(keyword, modelType, listType, industryId, currentPage, PAGE_SIZE, locationId, new CallbackListener<List<CouponBO>>() {
            @Override
            public void onSuccess(List<CouponBO> data) {
                categoryAdapter.addItems(data);
                for (CouponModel couponModel : data) {
                    Log.d("test", couponModel.getName());
                }
            }

            @Override
            public void onFailure(String errorCode, String message) {
                ToastUtil.showShort(CategoryActivity.this, message);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    @Override
    public void onClick(View view) {
        if (view == stationeryBtn) {
            industryId = 6;
        }
        if (view == foodBtn) {
            industryId = 5;
        }
        categoryAdapter.clearItems();
        getDatas(industryId);
    }
}
